package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * createTime：2021/8/18 11:23
 * description：QuittableTask
 */
public class QuittableTask implements Runnable {
    final int id;

    public QuittableTask(int id) {
        this.id = id;
    }

    private AtomicBoolean running = new AtomicBoolean(true);

    public void quit() {
        running.set(false);
    }

    @Override
    public void run() {
        while (running.get()) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                System.out.println(e.getMessage());
            }
        }
        System.out.print(id + " ");
    }
}
